package com.itheima.ydd.controller;

import com.itheima.ydd.common.R;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.YddArticle;
import com.itheima.ydd.entity.YddUser;
import com.itheima.ydd.service.IYddArticleService;
import com.itheima.ydd.service.IYddUserDataService;
import com.itheima.ydd.service.IYddUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IYddArticleService iYddArticleService;
    @Autowired
    private IYddUserDataService iYddUserDataService;
    @Autowired
    private IYddUserService iYddUserService;

    /**
     * 我的文章
     * @param limit
     * @param page
     * @return
     */
    @GetMapping("myArticle")
    public ResultData myArticle(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer limit,
                                HttpServletRequest request
                                ) {
        return iYddArticleService.myArticle(limit, page,request);
    }


    @GetMapping("getUserInfo")
    public ResultData getUserInfo() {
        ResultData getUserInfo = iYddUserService.getUserInfo();

        return getUserInfo;
    }

    /**
     * 修改文章
     * @param yddArticle
     * @return
     */
    @PostMapping("editArticle")
    public ResultData editArticle(@RequestBody YddArticle yddArticle){
        return iYddArticleService.editArticle(yddArticle);
    }

    /**
     * 修改用户资料
     * @return
     */
    @PostMapping("update")
    public ResultData updateUser(@RequestBody YddUser yddUser) {
        return iYddUserService.updateUser(yddUser);
    }

    /**
     * 点赞收藏&取消点赞收藏
     * @param type
     * @param article_id
     * @param action
     * @return
     */
    @GetMapping("userDataHandle")
    public ResultData userDataHandle(String type, String article_id, String action) {
        return iYddUserDataService.userDataHandle(type, article_id, action);
    }


    //    //点赞收藏查询
    @GetMapping("userDataList")
    public ResultData userDataLists(Integer page, Integer limit, Integer type) {
        return iYddUserDataService.userDataLists(page, limit, type);
    }

    /**
     * 发布文章
     * @param yddArticle
     * @return
     */
    @PostMapping("addArticle")
    public ResultData addArticle(@RequestBody YddArticle yddArticle, HttpServletRequest request) {
        return iYddArticleService.addArticle(yddArticle,request);
    }

    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("delArticle")
    public ResultData delArticle(String id){
        return iYddArticleService.delArticle(id);
    }
}
